package com.apes.fn.crm.customerExpand;

import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface FnCustomerInfoRepository extends CustomRepository<FnCustomerInfo, String> {

    FnCustomerInfo findByCarLicenseAndVendorCode(String carLicense, String vendorCode);

    Page<FnCustomerInfo> findAllByCarLicenseLikeOrMobileLikeOrRealnameLike(String carLicense, String mobile, String realname, Pageable pageable);

    Page<FnCustomerInfo> findAllByCarLicenseLikeOrRealnameLike(String carLicense, String realname, Pageable pageable);

    Page<FnCustomerInfo> findAllByCarLicenseLikeOrMobileLike(String carLicense, String mobile, Pageable pageable);

    @Query("SELECT a FROM FnCustomerInfo a WHERE a.vendorCode = :vendorCode and (a.carLicense like :carLicense or a.mobile like :mobile or a.realname like :realname)")
    Page<FnCustomerInfo> findAllByVendorCodeAndCarLicenseLikeOrMobileLikeOrRealnameLike(String vendorCode,String carLicense, String mobile, String realname, Pageable pageable);

    @Query("SELECT a FROM FnCustomerInfo a WHERE a.vendorCode = :vendorCode and (a.carLicense like :carLicense or  a.realname like :realname)")
    Page<FnCustomerInfo> findAllByVendorCodeAndCarLicenseLikeOrRealnameLike(String vendorCode,String carLicense, String realname, Pageable pageable);

    @Query("SELECT a FROM FnCustomerInfo a WHERE a.vendorCode = :vendorCode and (a.carLicense like :carLicense or  a.mobile like :mobile)")
    Page<FnCustomerInfo> findAllByVendorCodeAndCarLicenseLikeOrMobileLike(String vendorCode,String carLicense, String mobile, Pageable pageable);

    Page<FnCustomerInfo> findAllByVendorCodeAndCarLicenseOrMobileOrRealname(String vendorCode,String carLicense, String mobile,String realname, Pageable pageable);

}
